<template>
  <!-- 事业部列表 -->
  <div>
    <FilterTable
      ref="table"
      :dataSource="dataSource"
      :columns="columns"
      :isSelectColumn="false"
      :isToperInfo="false"
      :params="flterValue"
      :datakey="'records'"
      :formType="'show'"
      :onColumnsChange="columns => this.columns = columns"
      columnsRef="projectOperating_projram_commonForm_detail-infoCause_01"
    ></FilterTable>
    <!-- 事业部下发经销商列表 -->
    <BaseDialog
      title="事业部下发经销商列表"
      :visible.sync="visibleDealerDialog"
      width="700px"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <infoDealer ref="InfoDealerRef" v-model="dealerParams" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getShiYeDept } from '@/api/cms-api/projectOperating/program/push'; //事业部
import infoDealer from './detail-dealer'; //经销商列表
export default {
  mixins: [dictionary],
  components: {
    infoDealer
  },
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      activityDialogData: {},
      visibleDealerDialog: false, //是否显示经销商列表
      formValue: {},
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchParams: null, //ipa 接口
      arr: {},
      dealerParams: null, //经销商列表窗参数
      dataSource: []
    };
  },
  mounted() {
    //初始化事业部数据
    if (this.value != null) {
      this.init();
    }
  },
  methods: {
    async init() {
      this.arr.projectProgramId = this.value.rowData['projectProgramId'];
      this.arr.currentPage = 1;
      this.arr.pageNum = 1;
      this.arr.isDeleted = 0;
      this.arr.pageSize = 999;
      //加载事业部信息
      const res = await getShiYeDept(this.arr);
      // console.log(res,"事业部:res")

      if (res.resultCode === 200) {
        var result = res.data.records;
        this.dataSource = result; //res.data.records;
        this.formValue = this.dataSource;
      } else {
        this.$notify.error({ title: '提示信息', message: res.errMsg || 'getShiYeDept失败!' });
      }
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        // { title: '事业部代码', dataIndex: 'orgCode', sorter: true },
        { title: '事业部名称', dataIndex: 'orgName', sorter: true },
        {
          title: '事业部分配状态',
          dataIndex: 'orgStatus',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.orgStatus, '2528')}</span>;
          }
        },
        { title: '事业部分配说明', dataIndex: 'distributionDesc', sorter: true },
        { title: '事业部分派时间', dataIndex: 'distributionTime', sorter: true, dateFormat: 'yyyy-MM-dd' },
        {
          title: '经销商列表',
          dataIndex: 'dealerCount',
          sorter: true,
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.showDealerList(props.row, 'show')}>
                  {props.row.dealerCount}
                </el-button>
              </div>
            );
          }
        }
      ];
    },
    //显示事业部下发经销商列表
    showDealerList(rowData, formType) {
      //显示经销商列表
      let params = Object.assign({}, this.value);
      if (params != null && params.rowData != null) params.rowData.projectProgramOrgId = rowData['id'];
      this.dealerParams = params;
      this.visibleDealerDialog = true;
    }
  }
};
</script>
